<?php
namespace app\api\forms;

use Phalcon\Forms\Form;
use Phalcon\Mvc\Model;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\File;


class PromotionalForm extends Form
{
    public function initialize(Model $model)
    {
        $this->setEntity($model);

        if($this->request->hasFiles()){
            /* @var $files \Phalcon\Http\Request\File[]*/
            $files = $this->request->getUploadedFiles();
            foreach($files as $file){
                if(!$file->getError()){
                    $key = $file->getKey();
                    $filename = date('YmHis'.rand(10, 999999)).$file->getExtension();
                    $file->moveTo('uploads/promotional/'.$filename);
                    $model->$key = $filename;
                }
            }
        }

        $des = new Text("des");
        $des->setFilters(['string','trim']);

        $this->add($des);
        $this->add(new File("src"));
    }
}